#include <stdio.h>
#include <stdlib.h>
/**
*  Tutorial #11 (Characters and Strings)
*  Program to find permutations of given string
**/
int main6()
{
    printf("Enter the Arguments n and r\n");
    int n,r;
    char str[10],loc[10];
    scanf("%d%d",&n,&r);
    printf("Enter the String\n");
    scanf("%s",str);
    perMut(str,n,r,loc,0);
}

void perMut(char str[],int n,int r,char loc[],int m){
    if(r == 0){
       loc[m] = '\0';
       printf("%s\n",loc);
       return;
    }else{
        int i;
        for(i = 0;i<n;i++){
            char newList[n];
            loc[m] = str[i];
            deleteAndCreateList(str,n,i,newList);
            //printf("New List: %s\n",newList);
            perMut(newList,n-1,r-1,loc,m+1);
        }
    }
    return;
}

void deleteAndCreateList(char str[],int n,int i,char newList[]){
    int j;
    for(j = 0;j < i;j++)newList[j] = str[j];
    for(j = i;j < n-1;j++)newList[j] = str[j+1];
}
